<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>打字机效果</title>
  </head>
  <body>
    <div id="typing-text"></div>
    <script>
      function typeWriter(element, text, speed = 100) {
        let i = 0;
        function type() {
          if (i < text.length) {
            element.innerHTML += text.charAt(i);
            i++;
            setTimeout(type, speed);
          }
        }
        type();
      }

      // 使用示例
      const element = document.querySelector("#typing-text");
      typeWriter(element, "这是一段打字机效果文字", 100);
    </script>
  </body>
</html>
